package me.sdevil507.biz.fruit.repository;

import me.sdevil507.biz.fruit.po.FruitFeedBackPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: tips_back_end
 * @description: 成果专报反馈对象
 **/
public interface FruitSpecialFeedBackRepository extends JpaRepository<FruitFeedBackPO, Long>, JpaSpecificationExecutor<FruitFeedBackPO>, QuerydslPredicateExecutor<FruitFeedBackPO> {

    List<FruitFeedBackPO> getAllByFruitIdOrderByCreateTimeDesc(Long fruitId);

    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update FruitFeedBackPO a set a.isLook=true where a.fruitId=:fruitId")
    void updateFruitFeedBackByFruitId(@Param("fruitId") Long fruitId);

}
